package net.zoneland.knowledge.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

/**
 * 查询链路aop监控.
 * @author zmq
 * 2021/10/21 13:54
 */
@Aspect
@Component
@Lazy(false)
public class SearchOperationChainAspect {

    /**
     * 是否开启性能监控.
     */
    @Value("${stop.watch.enabled:false}")
    private boolean stopWatchEnabled;

    /**
     * 切点.
     */
    @Pointcut("execution(* net.zoneland.knowledge.service.impl.search.SearchOperationChain.searchOrDeal(..))")
    public void pointCut() {

    }

    /**
     * 环绕通知.
     * @param joinPoint 方法执行体
     * @return 返回结果
     * @throws Exception 异常
     */
    @Around("pointCut()")
    public Object around(final ProceedingJoinPoint joinPoint) throws Exception {
        return SearchOperationAopUtils.around(joinPoint, stopWatchEnabled);
    }
}
